/*global module:false*/
module.exports = function (grunt) {

  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('package.json'),
    banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
    '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
    '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
    '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
    ' Licensed <%= _.map(pkg.licenses, "type").join(", ") %> */\n',
    // Task configuration.
    clean: {
      build: {
        src: ["dist/**/*"]  //清空文件和文件夹
      }
    },
    bower: {
      install: {
        options: {
          copy: true,
          targetDir: './public/js',
          layout: 'byComponent',
          install: true,
          verbose: false,
          cleanTargetDir: false,
          cleanBowerDir: false,
          //bowerOptions: {}
        }
      }
    },
    requirejs: {
      build: {
        options: {
          baseUrl: './src/require/geek',//基本路径
          name: "main",
          //optimize: 'uglify',   //指定压缩工具类型  使用uglify工具压缩
          optimize: 'none',   //指定压缩工具类型  使用uglify工具压缩
          mainConfigFile: 'src/require/geek/config.js',  // requirejs 的配置文件，工具通过它来获取 requirejs 的配置信息
          //include:["util.js"],//需要包含的模块名称
          out: './dist/require/geek.min.js'   //压缩后的文件
        }
      }
    },
    concat: { //文件合并
      options: {
        stripBanners:true, //去掉代码中的注释
      },
      build: {
        options: {
          banner: "<%= banner %>",
          footer: ""
        },
        files: {
          'dist/common.js': ['src/common/Array.js', 'src/common/Date.js', 'src/common/JSON.js'],
          "dist/require/geek.js": ["src/require/geek/util.js", "src/require/geek/main.js"]
        }
      }
    },
    uglify: { // 文件压缩
      options: {
        //preserveComments: false, //不删除注释，还可以为 false（删除全部注释），some（保留@preserve @license @cc_on等注释）
        banner: "<%= banner %>"
      },
      common: {
        files: {
          'dist/common.min.js': ['src/common/Array.js', 'src/common/Date.js', 'src/common/JSON.js'],
          "dist/require/geek.min.js": ["src/require/geek/util.js", "src/require/geek/main.js"]
        }
      }
    },
    watch: {
      options: {
        nospawn: true
      },
      dev: {
        files: ['src/**/*.js'],
        tasks: ['clean', 'concat']
      }
    },
    connect: {
      server: {
        options: {
          port: 8080,
          protocol: "http",
          hostname: "localhost",
          open: true,
          keepalive: true
        }
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.loadNpmTasks('grunt-bower-task');
  grunt.loadNpmTasks("grunt-contrib-concat");
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-connect');

  // Default task.
  grunt.registerTask('default', ["clean", 'concat','bower','watch']);
  grunt.registerTask("release", ["clean", "uglify",'bower']);

};
